package com.base.cn.platform.os.controller.statistics;

import com.base.cn.platform.os.common.AdminBaseController;
import com.base.cn.platform.os.service.manage.statistics.trade.TradeStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 交易数据统计
 * @author s.li
 */
@Controller
@RequestMapping("/admin/stat")
public class TradeStatController extends AdminBaseController {

    @Autowired
    private TradeStatisticsService tradeStatisticsService;

    @RequestMapping("/trade")
    public String trade(){
        return resultPage("/statistics/trade/trade-statistics");
    }

    /**
     * 查看交易分析统计中的交易数据
     * @param type type 时间类型，1=今日实时，2=近7天（不包含当天），3=近30天（不包含当天），4=自定义（只可选当天之前的时间，且时间跨度不超过12月）
     * @param startTime 开始时间
     * @param endTime 结果时间
     * @return Map<String,Object>
     */
    @RequestMapping("/tradePayOrderNumList")
    @ResponseBody
    public Map<String,Object> tradePayOrderNumList(@RequestParam(value = "type",required = false,defaultValue = "1") int type,
                                                   @RequestParam(value = "startTime",required = false) Date startTime,
                                                   @RequestParam(value = "endTime",required = false) Date endTime){
        Map<String,Object> params = new HashMap<>();
        params.put("type",type);
        params.put("startTime",startTime);
        params.put("endTime",endTime);
        return tradeStatisticsService.tradePayOrderNumList(params);
    }

    /**
     * 查看交易分析统计中的交易数据
     * @return Map<String,Object>
     */
    @RequestMapping("/queryOrderTradeSpreadList")
    @ResponseBody
    public Map<String,Object> queryOrderTradeSpreadList(@RequestParam(value = "type",required = false,defaultValue = "1") int type,
                                                        @RequestParam(value = "startTime",required = false) Date startTime,
                                                        @RequestParam(value = "endTime",required = false) Date endTime){
        Map<String,Object> params = new HashMap<>();
        params.put("type",type);
        params.put("startTime",startTime);
        params.put("endTime",endTime);
        return tradeStatisticsService.queryOrderTradeSpreadList(params);
    }

    /**
     * 交易支付方式比例图
     * @return Map<String,Object>
     */
    @RequestMapping("/queryOrderPayTypeOrderNum")
    @ResponseBody
    public Map<String,Object> queryOrderPayTypeOrderNum(@RequestParam(value = "type",required = false,defaultValue = "1") int type,
                                                        @RequestParam(value = "startTime",required = false) Date startTime,
                                                        @RequestParam(value = "endTime",required = false) Date endTime){
        Map<String,Object> params = new HashMap<>();
        params.put("type",type);
        params.put("startTime",startTime);
        params.put("endTime",endTime);
        return tradeStatisticsService.queryOrderPayTypeOrderNum(params);
    }


    /**
     * 交易支付渠道
     * @return Map<String,Object>
     */
    @RequestMapping("/queryPayOrderFormNumData")
    @ResponseBody
    public Map<String,Object> queryPayOrderFormNumData(@RequestParam(value = "type",required = false,defaultValue = "1") int type,
                                                       @RequestParam(value = "startTime",required = false) Date startTime,
                                                       @RequestParam(value = "endTime",required = false) Date endTime){
        Map<String,Object> params = new HashMap<>();
        params.put("type",type);
        params.put("startTime",startTime);
        params.put("endTime",endTime);
        return tradeStatisticsService.queryPayOrderFormNumData(params);
    }
}
